package com.woniu.demo.controller;

import com.woniu.demo.entity.req.Student;
import com.woniu.demo.entity.req.Student2;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * created by woniu201
 * created in 2018/6/21
 */
@RestController
public class TestController {


    //******************************** content-type:www-urlencode *******************************************/
    @RequestMapping(value = "/test1", method = RequestMethod.POST)
    public Student test1(Student student, Student2 student2){
        System.out.println(student.getToken());
        System.out.println(student.getName());
        System.out.println(student.getAge());

        System.out.println("2:" + student2.getToken());
        return student;
    }

    @RequestMapping(value = "/test2", method = RequestMethod.GET)
    public Student test2(Student student, Student2 student2){
        System.out.println(student.getToken());
        System.out.println(student.getName());
        System.out.println(student.getAge());

        System.out.println("2:" + student2.getToken());
        return student;
    }

    //*****************************************************************************************************/

    //****************************** content-type:application-json ****************************************/
    @RequestMapping(value = "/test3", method = RequestMethod.PUT)
    public ResponseEntity<?> test3(@RequestBody Student student, @RequestBody Student2 student2, HttpServletRequest req){
        System.out.println(student.getToken());
        System.out.println(student.getName());
        System.out.println(student.getAge());

        System.out.println("2:" + student2.getToken());
//        Map<String, String> map = new HashMap<>();
//        map.put("a", "1111");
//        map.put("b", "2222");

        System.out.println(req.getRemoteHost());
        System.out.println(req.getRemotePort());
        System.out.println(req.getRemoteAddr());

//        ResponseEntity.BodyBuilder builder = ResponseEntity.status(HttpStatus.OK);
//        return builder.body(student);
        return new ResponseEntity<>(student, HttpStatus.OK);
    }

    @RequestMapping(value = "/test4", method = RequestMethod.GET)
    public ResponseEntity<?> test4( Student student, Student2 student2){
        System.out.println(student.getToken());
        System.out.println(student.getName());
        System.out.println(student.getAge());

        System.out.println("2:" + student2.getToken());
        return new ResponseEntity<>(student, HttpStatus.OK);
    }
}
